package 线程;

public class Ticket implements Runnable{

	public Integer count = 50;
	@Override
	public void run() {
		while(true){
			shoupiao(this);
		}
		
	}
	
	public synchronized void shoupiao(Ticket ticket){
		if(this.count > 0){
			System.out.println(Thread.currentThread().getName()
					+ "售出车票，ticket 号为： " + this.count --);
			
		}
        
	}
	
	public static void main(String[] args) {
		Ticket t = new Ticket();
		Thread t1 = new Thread(t);
		t1.setName("Thread 1 ");
		Thread t2 = new Thread(t);
		t2.setName("Thread 2 ");
		Thread t3 = new Thread(t);
		t3.setName("Thread 3 ");
		t1.start();
		t2.start();
		t3.start();
	}

}
